<!-- 课程卡片 -->
<template>
  <div class="courseCard" @click="toDetails">
    <div class="cardBanner">
      <img
        class="cardImg"
        :src="$getImageUrl(cardData.originImg)"
        alt=""
        srcset=""
      />
      <div class="cardTag">{{ cardData.categoryName }}</div>
    </div>
    <div class="cardInfo">
      <div class="cardTitle moreHidden">
        {{ cardData.name }}
      </div>
      <div class="cardOther">
        <div class="lecturer oneHidden">讲师：{{ cardData.speaker || '无' }}</div>
        <div class="booking">
          <img src="@/assets/users.png" alt="" />
          {{ cardData.joins || 0 }}人学习
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CourseCard',
  props: {
    cardData: {
      type: Object,
      default: () => {
        return {
          objectId: 0,
          originImg: '',
          name: '课程名称',
          speaker: '讲师名称',
          likes: 0,
        };
      },
    },
  },
  data() {
    return {};
  },
  methods: {
    toDetails() {
      const url = this.$router.resolve({
        path: '/courseDetails',
        query: {
          id: this.cardData.objectId
        }
      }).href;
      window.open(url, '_blank');
    },
  },
};
</script>

<style scoped lang="scss">
.courseCard {
  width: 326px;
  height: 297px;
  border-radius: 8px;
  box-shadow: $box-shadow;
  background: #fff;
  cursor: pointer;
  &:hover {
    box-shadow: $box-shadow-hover;
  }

  .cardBanner {
    width: 100%;
    height: 196px;
    position: relative;
    background: #fff;
    overflow: hidden;
    display: flex;
    align-items: center;
    border-radius: 8px 8px 0 0;

    .cardImg {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
    .cardTag {
      color: #fff;
      padding: 4px 6px;
      border-radius: 2px 0px 0px 0px;
      background: rgba(0, 0, 0, 0.5);
      position: absolute;
      top: 12px;
      right: 12px;
      font-size: 12px;
      font-weight: 600;
      line-height: 16.8px;
    }
  }
  .cardInfo {
    padding: 12px 16px 0;
    .cardTitle {
      width: 100%;
      height: 42px;
      font-size: 14px;
      font-weight: 600;
      line-height: 21px;
      color: $text-title-color;
      -webkit-line-clamp: 2;
    }
    .cardOther {
      display: flex;
      align-items: center;
      margin-top: 12px;
      justify-content: space-between;
      .lecturer {
        height: 18px;
        line-height: 18px;
        font-size: 12px;
        font-weight: 400;
        color: $text-color;
        margin-right: 6px;
      }
      .booking {
        color: $text-color-secondary;
        font-size: 12px;
        font-weight: 400;
        line-height: 18px;
        display: flex;
        align-items: center;
        flex-shrink: 0;
        img {
          widows: 14px;
          height: 14px;
          margin-right: 4px;
        }
      }
    }
  }
}
</style>
